
<style>
.affix{top:10px;}
.head-style-list li,.editor-template-list li{cursor: pointer;}
.baomings-bulk-add {position:relative;padding: 10px;margin-bottom: 10px;border: 1px solid #dddddd;}
.item-delete{position: absolute;right:5px;top: 0px;font-size:20px;z-index:1;}
.form-control {
    background: rgb(251,251,251);
    border-radius: 3px;
}
.hidePrice .item-price{display:none !important;}
.fa-plus-circle,.fa-minus-circle{font-size:18px;margin-left:10px;cursor:pointer;}
.pickup-addresses p:nth-child(1) .fa-minus-circle{display:none;}
.pricerule-bulk-add:nth-child(1) .fa-minus-circle{display:none;}
.pricerule-bulk-add{padding-left:30px;}
.navbar-fixed-bottom {
	background-color: #f23030;
	border-top: 0;
}
</style>

{{$this->Form->create('WxActivity',array('id'=>'WxActivityAddForm','role'=>'form'))}}
		
	<div class="tab-content" style="margin-bottom:50px;">
			
		<div role="tabpanel" class="tab-pane active" id="chi-info">
			
			<div class="form-group">
				<label class="control-label" for="WxActivityName">活动名称</label>
					{{$this->Form->hidden('id')}}
					{{$this->Form->hidden('model',array('value'=>'Product'))}}
					{{$this->Form->hidden('status',array('default'=>1))}}					
					{{$this->Form->input('name',array('class'=>'form-control','div'=>false,'label'=>false,'required'=>'required'))}}
			</div>
			
			<div class="form-group">
				<label class="control-label" for="WxActivitySummary">活动摘要</label>
					{{$this->Form->input('summary',array('class'=>'form-control','rows'=>'6','div'=>false,'required'=>'required','label'=>false,))}}
			</div>
			
			<div class="form-group">
				<label class="control-label" for="WxStorefrontCoverImg">封面图片</label>
					{{$this->Swfupload->load('coverimg',array(
					'label'=>false,'modelClass'=>'WxActivity',
					'no_db'=>0,'upload_limit'=>1,
					'file_types'=> '*.jpg;*.gif;*.png;*.bmp',
					'isadmin'=>false
					))}}
			</div>			
		<div>
       
		<!--
		<div class="form-group">
			<label class="col-xs-3 control-label" for="WxActivityAddress">有效时间</label>
			<div class="col-xs-9 controls form-inline">
				{{$this->Form->input('expired',array('class'=>'form-control','default'=>0,'div'=>false,'label'=>false,))}}
				<p>按开始结束时间生效</p>
			</div>
		</div>
						
			<div class="form-group">
				<label class="col-xs-3 control-label" for="WxStorefrontPriority">开始时间</label>
				<div class="col-xs-9 controls form-inline">
					{{$this->Form->input('started',array('class'=>'form-control','type'=>'datetime','dateFormat'=>'YMD','timeFormat'=>24,
					'monthNames'=> array(
						1=>'1月',2=>'2月',3=>'3月',4=>'4月',5=>'5月',6=>'6月',
						7=>'7月',8=>'8月',9=>'9月',10=>'10月',11=>'11月',12=>'12月',
					),
					'div'=>false,'label'=>false,))}}
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 control-label" for="WxStorefrontPriority">结束时间</label>
				<div class="col-xs-9 controls form-inline">
					{{$this->Form->input('ended',array('class'=>'form-control','type'=>'datetime','dateFormat'=>'YMD','timeFormat'=>24,
					'monthNames'=> array(
						1=>'1月',2=>'2月',3=>'3月',4=>'4月',5=>'5月',6=>'6月',
						7=>'7月',8=>'8月',9=>'9月',10=>'10月',11=>'11月',12=>'12月',
					),
					'div'=>false,'label'=>false,))}}
				</div>
			</div> -->
	
		<div class="form-group">
			<button class="btn btn-primary btn-lg {{if $is_mobile}}btn-block navbar-fixed-bottom{{/if}}" type="submit">
				{{if $current_action=='add'}}完成创建{{else}}保存修改{{/if}}
			</button>
		</div>
	</div>
{{$this->Form->end()}}

<script>

$(function(){

	$('#WxActivityHidePrice').click(function(){
		if(this.checked){
			$('#WxActivityAddForm').addClass('hidePrice');
			$('#WxActivityAddForm .item-price :input').each(function(){
				$(this).data('val',this.value);
				this.value = 0;
			})
		}
		else{
			$('#WxActivityAddForm').removeClass('hidePrice');
			$('#WxActivityAddForm .item-price :input').each(function(){
				$(this).val($(this).data('val'));
			})
		}	
	})
	
	$('#WxActivityAddForm').data('submitCallback',function(request){
		if(request.ret == 0 && request.data.WxActivity.id > 0) {
			showSuccessMessage('活动已成功{{if $current_action=='add'}}创建{{else}}修改{{/if}}，即将进入详情页');
			window.location = '/wx_activities/view/' + request.data.WxActivity.id ;
		}
	});

	$(document).on('click','#price-rules .fa-plus-circle',function(){
		var clone = $(this).parents('.pricerule-bulk-add:first').clone();
        clone.find('input').val('');
        clone.insertAfter( $(this).parents('.pricerule-bulk-add:first') );
        
        $('.pricerule-bulk-add').each(function(i){
        	$(this).find(':input').each(function(){
	            var name = $(this).attr('name');
	            //alert(name.replace(/\[\d*\]/,'[10]'));
	            $(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
	        })
        });
	});
	$(document).on('click','.pricerule-bulk-add .fa-minus-circle',function(){
	    if( $('.pricerule-bulk-add').size() > 1 ) {
            $(this).parents('.pricerule-bulk-add:first').remove();
		}
		else{
            $(this).parents('.pricerule-bulk-add:first').find(':input').val('');
		}
    });


    $(document).on('click','.serialize_fields .fa-plus-circle',function(){
        var clone = $(this).parents('p:first').clone();
        clone.find('input').val('');
        clone.insertAfter( $(this).parents('p:first') );

        $('.serialize_fields p').each(function(i){
            $(this).find(':input').each(function(){
                var name = $(this).attr('name');
                //alert(name.replace(/\[\d*\]/,'[10]'));
                $(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
            });
		});

    });
    $(document).on('click','.serialize_fields .fa-minus-circle',function(){
        if( $('.serialize_fields p').size() > 1) {
            $(this).parents('p:first').remove();
		}
        else{
            $(this).parents('p:first').find(':input').val('');
        }
    });

	$(document).on('click','.pickup-addresses .fa-plus-circle',function(){
	    var clone = $(this).parents('p:first').clone();
        clone.find('input').val('');
        clone.insertAfter( $(this).parents('p:first') );
        
        $('.pickup-addresses').find(':input').each(function(i){
            var name = $(this).attr('name');
            //alert(name.replace(/\[\d*\]/,'[10]'));
            $(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
        });
        
	});
    $(document).on('click','.pickup-addresses .fa-minus-circle',function(){
        if( $('.pickup-addresses p').size() > 1) {
            $(this).parents('p:first').remove();
        }
        else{
            $(this).parents('p:first').find(':input').val('');
        }
    });

    $(document).on('change', '.serialize-type', function() {
        var txt = $('option:selected',this).text();
        if($.inArray(txt,['身份证','护照','邮箱','日期']) >= 0 ) {
            $(this).siblings('.serialize-name').val( txt );
        }
        else{
            var txt = $(this).siblings('.serialize-name').val( );
            if($.inArray(txt,['身份证','护照','邮箱','日期']) >= 0 ) {
                $(this).siblings('.serialize-name').val('');
            }
		}
    });
	
	$(document).on('click','.bulk-add-new',function(){
		var obj = $('.baomings-bulk-add:last');

		var newobj = obj.clone();newobj.find(':input').val('');
		newobj.insertAfter(obj);
		
		$('.baomings-bulk-add').each(function(i){
			$(this).find(':input').each(function(){
				var name = $(this).attr('name');
				//alert(name.replace(/\[\d*\]/,'[10]'));
				$(this).attr('name',name.replace(/\[\d*\]/,'['+i+']'));
			});
		});		
	})
	$(document).on('click','.item-delete',function(){
		if( $('.baomings-bulk-add').size() > 1 ){
			var id = $(this).data('id');
			if( id > 0 ) {
				if(confirm('请注意删除已添加项，可能影响已提交的数据，是否确认删除？')) {
					ajaxAction('/baomings/delete/'+id,null,null,function(request){
						if(request.ret == 0) {
							showSuccessMessage(request.msg);
							$('#item-'+id).remove();
						}
						else{
							showErrorMessage(request.msg);
						}
						

					});
				}
			}
			else{
				$(this).parents('.baomings-bulk-add').remove();	
			}
		}
		else{
			alert('项目至少要保留1个');		
		}		
	})
})
</script>